--[[
   ______________
  // ||             || \\
 ||  || VIDEO ||  ||
  \\ || ________|| //

]]

BG_PALETTE = 0x05000000
BG_PALETTE_SUB = 0x05000400

SPRITE_PALETTE = 0x05000200
SPRITE_PALETTE_SUB = 0x05000600

BG_GFX = 0x6000000
BG_GFX_SUB = 0x6200000
SPRITE_GFX = 0x6400000
SPRITE_GFX_SUB = 0x6600000

VRAM_0 = 0x6000000
VRAM_ = 0x6800000

VRAM_A = 0x6800000
VRAM_B = 0x6820000
VRAM_C = 0x6840000
VRAM_D = 0x6860000
VRAM_E = 0x6880000
VRAM_F = 0x6890000
VRAM_G = 0x6894000
VRAM_H = 0x6898000
VRAM_I = 0x68A0000

OAM = 0x07000000
OAM_SUB = 0x07000400

function RGB15(r,g,b) return bit.bor(r, bit.bor(bit.blshift(g, 5), bit.blshift(b,10))) end
function RGB5(r,g,b) return bit.bor(r, bit.bor(bit.blshift(g, 5), bit.blshift(b, 10))) end
function RGB8(r,g,b) return bit.bor(bit.brshift(r,3), bit.blshift(bit.brshift(g, 3), 5), bit.blshift(bit.brshift(g, b), 10)) end
function ARGB16(a, r, g, b) return bit.bor(bit.blshift(a, 15), bit.bor(r, bit.bor(bit.blshift(g, 5), bit.blshift(b,10)))) end

-- //Vram Control\\ --
VRAM_CR = 0x04000240
VRAM_A_CR = 0x04000240
VRAM_B_CR = 0x04000241
VRAM_C_CR = 0x04000242
VRAM_D_CR = 0x04000243
VRAM_E_CR = 0x04000244
VRAM_F_CR = 0x04000245
VRAM_G_CR = 0x04000246
WRAM_CR = 0x04000247
VRAM_H_CR = 0x04000248
VRAM_I_CR = 0x04000249

VRAM_ENABLE = bit.blshift(1,7)

function VRAM_OFFSET(n) return bit.blshift(n, 3) end

-- //Allowed VRAM bank A modes\\ --
VRAM_A_LCD = 0 -- //maps vram a to lcd\\ --
VRAM_A_MAIN_BG = 1 -- //maps vram a to main engine background slot 0\\ --
VRAM_A_MAIN_BG_0x06000000 = bit.bor(1, VRAM_OFFSET(0)) -- //maps vram a to main engine background slot 0\\ --
VRAM_A_MAIN_BG_0x06020000 = bit.bor(1, VRAM_OFFSET(1)) -- //maps vram a to main engine background slot 1\\ --
VRAM_A_MAIN_BG_0x06040000 = bit.bor(1, VRAM_OFFSET(2)) -- //maps vram a to main engine background slot 2\\ --
VRAM_A_MAIN_BG_0x06060000 = bit.bor(1, VRAM_OFFSET(3)) -- //maps vram a to main engine background slot 3\\ --
VRAM_A_MAIN_SPRITE = 2 -- //maps vram a to main engine sprites slot 0\\ --
VRAM_A_MAIN_SPRITE_0x06400000 = bit.bor(2, VRAM_OFFSET(0)) -- // maps vram a to main engine sprites slot 0\\ --
VRAM_A_MAIN_SPRITE_0x06420000 = bit.bor(2, VRAM_OFFSET(1)) -- // maps vram a to main engine sprites slot 1\\ --
VRAM_A_TEXTURE = 3 -- //maps vram a to 3d texture slot 0\\ --
VRAM_A_TEXTURE_SLOT0 = bit.bor(3, VRAM_OFFSET(0)) -- //maps vram a to 3d texture slot 0\\ --
VRAM_A_TEXTURE_SLOT1 = bit.bor(3, VRAM_OFFSET(1)) -- //maps vram a to 3d texture slot 1\\ --
VRAM_A_TEXTURE_SLOT2 = bit.bor(3, VRAM_OFFSET(2)) -- //maps vram a to 3d texture slot 2\\ --
VRAM_A_TEXTURE_SLOT3 = bit.bor(3, VRAM_OFFSET(3)) -- //maps vram a to 3d texture slot 3\\ --

-- //Allowed VRAM bank B modes\\ --
VRAM_B_LCD = 0 -- //maps vram b to lcd\\ --
VRAM_B_MAIN_BG = bit.bor(1, VRAM_OFFSET(1)) -- //maps vram b to main engine background slot 1\\ --
VRAM_B_MAIN_BG_0x06000000 = bit.bor(1, VRAM_OFFSET(0)) -- //maps vram b to main engine background slot 0\\ --
VRAM_B_MAIN_BG_0x06020000 = bit.bor(1, VRAM_OFFSET(1)) -- //maps vram b to main engine background slot 1\\ --
VRAM_B_MAIN_BG_0x06040000 = bit.bor(1, VRAM_OFFSET(2)) -- //maps vram b to main engine background slot 2\\ --
VRAM_B_MAIN_BG_0x06060000 = bit.bor(1, VRAM_OFFSET(3)) -- //maps vram b to main engine background slot 3\\ --
VRAM_B_MAIN_SPRITE = 2 -- //maps vram b to main engine sprites slot 0\\ --
VRAM_B_MAIN_SPRITE_0x06400000 = bit.bor(2, VRAM_OFFSET(0)) -- // maps vram b to main engine sprites slot 0\\ --
VRAM_B_MAIN_SPRITE_0x06420000 = bit.bor(2, VRAM_OFFSET(1)) -- // maps vram b to main engine sprites slot 1\\ --
VRAM_B_TEXTURE = bit.bor(3, VRAM_OFFSET(1)) -- //maps vram b to 3d texture slot 1\\ --
VRAM_B_TEXTURE_SLOT0 = bit.bor(3, VRAM_OFFSET(0)) -- //maps vram b to 3d texture slot 0\\ --
VRAM_B_TEXTURE_SLOT1 = bit.bor(3, VRAM_OFFSET(1)) -- //maps vram b to 3d texture slot 1\\ --
VRAM_B_TEXTURE_SLOT2 = bit.bor(3, VRAM_OFFSET(2)) -- //maps vram b to 3d texture slot 2\\ --
VRAM_B_TEXTURE_SLOT3 = bit.bor(3, VRAM_OFFSET(3)) -- //maps vram b to 3d texture slot 3\\ --

-- //Allowed vram bank C modes\\ --
VRAM_C_LCD = 0 -- //maps vram c to lcd\\ --
VRAM_C_MAIN_BG = bit.bor(1, VRAM_OFFSET(2)) -- //maps vram c to main engine background slot 2\\ --
VRAM_C_MAIN_BG_0x06000000 = bit.bor(1, VRAM_OFFSET(0)) -- //maps vram c to main engine background slot 0\\ --
VRAM_C_MAIN_BG_0x06020000 = bit.bor(1, VRAM_OFFSET(1)) -- //maps vram c to main engine background slot 1\\ --
VRAM_C_MAIN_BG_0x06040000 = bit.bor(1, VRAM_OFFSET(2)) -- //maps vram c to main engine background slot 2\\ --
VRAM_C_MAIN_BG_0x06060000 = bit.bor(1, VRAM_OFFSET(3)) -- //maps vram c to main engine background slot 3\\ --
VRAM_C_ARM7 = 2 -- //maps vram c to ARM7 workram slot 0\\ --
VRAM_C_ARM7_0x06000000 =  bit.bor(2, VRAM_OFFSET(0)) -- //maps vram c to ARM7 workram slot 0\\ --
VRAM_C_ARM7_0x06020000 =  bit.bor(2, VRAM_OFFSET(1)) -- //maps vram c to ARM7 workram slot 1\\ --
VRAM_C_SUB_BG = 4 -- //maps vram c to sub engine background slot 0\\ --
VRAM_C_SUB_BG_0x06200000 = bit.bor(4, VRAM_OFFSET(0)) -- //maps vram c to sub engine background slot 0\\ --
VRAM_C_TEXTURE = bit.bor(3, VRAM_OFFSET(2)) -- //maps vram c to 3d texture slot 2\\ --
VRAM_C_TEXTURE_SLOT0 = bit.bor(3, VRAM_OFFSET(0)) -- //maps vram c to 3d texture slot 0\\ --
VRAM_C_TEXTURE_SLOT1 = bit.bor(3, VRAM_OFFSET(1)) -- //maps vram c to 3d texture slot 1\\ --
VRAM_C_TEXTURE_SLOT2 = bit.bor(3, VRAM_OFFSET(2)) -- //maps vram c to 3d texture slot 2\\ --
VRAM_C_TEXTURE_SLOT3 = bit.bor(3, VRAM_OFFSET(3)) -- //maps vram c to 3d texture slot 3\\ --

-- //Allowed vram bank D modes\\ --
VRAM_D_LCD = 0 -- //maps vram d to lcd\\ --
VRAM_D_MAIN_BG = bit.bor(1, VRAM_OFFSET(3)) -- //maps vram d to main engine background slot 3\\ --
VRAM_D_MAIN_BG_0x06000000 = bit.bor(1, VRAM_OFFSET(0)) -- //maps vram d to main engine background slot 0\\ --
VRAM_D_MAIN_BG_0x06020000 = bit.bor(1, VRAM_OFFSET(1)) -- //maps vram d to main engine background slot 1\\ --
VRAM_D_MAIN_BG_0x06040000 = bit.bor(1, VRAM_OFFSET(2)) -- //maps vram d to main engine background slot 2\\ --
VRAM_D_MAIN_BG_0x06060000 = bit.bor(1, VRAM_OFFSET(3)) -- //maps vram d to main engine background slot 3\\ --
VRAM_D_ARM7 = bit.bor(2, VRAM_OFFSET(1)) -- //maps vram d to ARM7 workram slot 1\\ --
VRAM_D_ARM7_0x06000000 =  bit.bor(2, VRAM_OFFSET(0)) -- //maps vram d to ARM7 workram slot 0\\ --
VRAM_D_ARM7_0x06020000 =  bit.bor(2, VRAM_OFFSET(1)) -- //maps vram d to ARM7 workram slot 1\\ --
VRAM_D_SUB_SPRITE = 4 -- //maps vram d to sub engine sprites slot 0\\ --
VRAM_D_TEXTURE = bit.bor(3, VRAM_OFFSET(3)) -- //maps vram d to 3d texture slot 3\\ --
VRAM_D_TEXTURE_SLOT0 = bit.bor(3, VRAM_OFFSET(0)) -- //maps vram d to 3d texture slot 0\\ --
VRAM_D_TEXTURE_SLOT1 = bit.bor(3, VRAM_OFFSET(1)) -- //maps vram d to 3d texture slot 1\\ --
VRAM_D_TEXTURE_SLOT2 = bit.bor(3, VRAM_OFFSET(2)) -- //maps vram d to 3d texture slot 2\\ --
VRAM_D_TEXTURE_SLOT3 = bit.bor(3, VRAM_OFFSET(3)) -- //maps vram d to 3d texture slot 3\\ --

-- //Allowed vram bank E modes\\ --
VRAM_E_LCD = 0 -- //maps vram e to lcd\\ --
VRAM_E_MAIN_BG = 1 -- //maps vram e to main engine background first half of slot 0\\ --
VRAM_E_MAIN_SPRITE = 2 -- //maps vram e to main engine sprites first half of slot 0\\ --
VRAM_E_TEX_PALETTE = 3 -- //maps vram e to 3d texture palette slot 0-3\\ --
VRAM_E_BG_EXT_PALETTE = 4 -- //maps vram e to main engine background extended palette\\ --

-- //Allowed vram bank F modes\\ --
VRAM_F_LCD = 0 -- //maps vram f to lcd\\ --
VRAM_F_MAIN_BG = 1 -- //maps vram f to main engine background first part of slot 0\\ --
VRAM_F_MAIN_BG_0x06000000 = bit.bor(1,  VRAM_OFFSET(0)) -- //maps vram f to main engine background first part of slot 0\\ --
VRAM_F_MAIN_BG_0x06004000 = bit.bor(1,  VRAM_OFFSET(1)) -- //maps vram f to main engine background second part of slot 0\\ --
VRAM_F_MAIN_BG_0x06010000 = bit.bor(1,  VRAM_OFFSET(2)) -- //maps vram f to main engine background second half of slot 0\\ --
VRAM_F_MAIN_BG_0x06014000 = bit.bor(1,  VRAM_OFFSET(3)) -- //maps vram f to main engine background second part of second half of slot 0\\ --
VRAM_F_MAIN_SPRITE = 2 -- //maps vram f to main engine sprites first part of slot 0\\ --
VRAM_F_MAIN_SPRITE_0x06400000 = bit.bor(2,  VRAM_OFFSET(0)) -- //maps vram f to main engine sprites first part of slot 0\\ --
VRAM_F_MAIN_SPRITE_0x06404000 = bit.bor(2,  VRAM_OFFSET(1)) -- //maps vram f to main engine sprites second part of slot 0\\ --
VRAM_F_MAIN_SPRITE_0x06410000 = bit.bor(2,  VRAM_OFFSET(2)) -- //maps vram f to main engine sprites second half of slot 0\\ --
VRAM_F_MAIN_SPRITE_0x06414000 = bit.bor(2,  VRAM_OFFSET(3)) -- //maps vram f to main engine sprites second part of second half of slot 0\\ --
VRAM_F_TEX_PALETTE = 3 -- //maps vram f to 3d texture palette slot 0\\ --
VRAM_F_TEX_PALETTE_SLOT0 = bit.bor(3,  VRAM_OFFSET(0)) -- //maps vram f to 3d texture palette slot 0\\ --
VRAM_F_TEX_PALETTE_SLOT1 = bit.bor(3,  VRAM_OFFSET(1)) -- //maps vram f to 3d texture palette slot 1\\ --
VRAM_F_TEX_PALETTE_SLOT4 = bit.bor(3,  VRAM_OFFSET(2)) -- //maps vram f to 3d texture palette slot 4\\ --
VRAM_F_TEX_PALETTE_SLOT5 = bit.bor(3,  VRAM_OFFSET(3)) -- //maps vram f to 3d texture palette slot 5\\ --
VRAM_F_BG_EXT_PALETTE = 4 -- //maps vram f to main engine background extended palette slot 0 and 1\\ --
VRAM_F_BG_EXT_PALETTE_SLOT01 = bit.bor(4,  VRAM_OFFSET(0)) -- //maps vram f to main engine background extended palette slot 0 and 1\\ --
VRAM_F_BG_EXT_PALETTE_SLOT23 = bit.bor(4,  VRAM_OFFSET(1)) -- //maps vram f to main engine background extended palette slot 2 and 3\\ --
VRAM_F_SPRITE_EXT_PALETTE = 5 -- //maps vram f to main engine sprites extended palette\\ --

-- //Allowed vram bank G modes\\ --
VRAM_G_LCD = 0 -- //maps vram g to lcd\\ --
VRAM_G_MAIN_BG = 1 -- //maps vram g to main engine background first part of slot 0\\ --
VRAM_G_MAIN_BG_0x06000000 = bit.bor(1,  VRAM_OFFSET(0)) -- //maps vram g to main engine background first part of slot 0\\ --
VRAM_G_MAIN_BG_0x06004000 = bit.bor(1,  VRAM_OFFSET(1)) -- //maps vram g to main engine background second part of slot 0\\ --
VRAM_G_MAIN_BG_0x06010000 = bit.bor(1,  VRAM_OFFSET(2)) -- //maps vram g to main engine background second half of slot 0\\ --
VRAM_G_MAIN_BG_0x06014000 = bit.bor(1,  VRAM_OFFSET(3)) -- //maps vram g to main engine background second part of second half of slot 0\\ --
VRAM_G_MAIN_SPRITE = 2 -- //maps vram g to main engine sprites first part of slot 0\\ --
VRAM_G_MAIN_SPRITE_0x06400000 = bit.bor(2,  VRAM_OFFSET(0)) -- //maps vram g to main engine sprites first part of slot 0\\ --
VRAM_G_MAIN_SPRITE_0x06404000 = bit.bor(2,  VRAM_OFFSET(1)) -- //maps vram g to main engine sprites second part of slot 0\\ --
VRAM_G_MAIN_SPRITE_0x06410000 = bit.bor(2,  VRAM_OFFSET(2)) -- //maps vram g to main engine sprites second half of slot 0\\ --
VRAM_G_MAIN_SPRITE_0x06414000 = bit.bor(2,  VRAM_OFFSET(3)) -- //maps vram g to main engine sprites second part of second half of slot 0\\ --
VRAM_G_TEX_PALETTE = 3 -- //maps vram g to 3d texture palette slot 0\\ --
VRAM_G_TEX_PALETTE_SLOT0 = bit.bor(3,  VRAM_OFFSET(0)) -- //maps vram g to 3d texture palette slot 0\\ --
VRAM_G_TEX_PALETTE_SLOT1 = bit.bor(3,  VRAM_OFFSET(1)) -- //maps vram g to 3d texture palette slot 1\\ --
VRAM_G_TEX_PALETTE_SLOT4 = bit.bor(3,  VRAM_OFFSET(2)) -- //maps vram g to 3d texture palette slot 4\\ --
VRAM_G_TEX_PALETTE_SLOT5 = bit.bor(3,  VRAM_OFFSET(3)) -- //maps vram g to 3d texture palette slot 5\\ --
VRAM_G_BG_EXT_PALETTE = 4 -- //maps vram g to main engine background extended palette slot 0 and 1\\ --
VRAM_G_BG_EXT_PALETTE_SLOT01 = bit.bor(4,  VRAM_OFFSET(0)) -- //maps vram g to main engine background extended palette slot 0 and 1\\ --
VRAM_G_BG_EXT_PALETTE_SLOT23 = bit.bor(4,  VRAM_OFFSET(1)) -- //maps vram g to main engine background extended palette slot 2 and 3\\ --
VRAM_G_SPRITE_EXT_PALETTE = 5 -- //maps vram g to main engine sprites extended palette\\ --

-- // Allowed VRAM bank H modes \\ --
VRAM_H_LCD = 0 -- // maps vram h to lcd\\ --
VRAM_H_SUB_BG = 1 -- // maps vram h to sub engine background first 2 parts of slot 0\\ --
VRAM_H_SUB_BG_EXT_PALETTE = 2 -- // maps vram h to sub engine background extended palette\\ --

-- //Allowed VRAM bank I modes\\ --
VRAM_I_LCD = 0 -- //maps vram i to lcd\\ --
VRAM_I_SUB_BG_0x06208000 = 1 -- //maps vram i to sub engine background thirth part of slot 0\\ --
VRAM_I_SUB_SPRITE = 2 -- //maps vram i to sub engine sprites\\ --
VRAM_I_SUB_SPRITE_EXT_PALETTE = 3 -- //maps vram i to sub engine sprites extended palette\\ --

--[[function VRAM.setBankA(a) VRAM_A_CR = bit.bor(VRAM_ENABLE, a) end
function VRAM.setBankB(b) VRAM_B_CR = bit.bor(VRAM_ENABLE, b) end
function VRAM.setBankC(c) VRAM_C_CR = bit.bor(VRAM_ENABLE, c) end
function VRAM.setBankD(d) VRAM_D_CR = bit.bor(VRAM_ENABLE, d) end
function VRAM.setBankE(e) VRAM_E_CR = bit.bor(VRAM_ENABLE, e) end
function VRAM.setBankF(f) VRAM_F_CR = bit.bor(VRAM_ENABLE, f) end
function VRAM.setBankG(g) VRAM_G_CR = bit.bor(VRAM_ENABLE, g) end
function VRAM.setBankH(h) VRAM_H_CR = bit.bor(VRAM_ENABLE, h) end
function VRAM.setBankI(i) VRAM_I_CR = bit.bor(VRAM_ENABLE, i) end]]


-- //Display control registers\\ --
REG_DISPCNT = 0x04000000
REG_DISPCNT_SUB = 0x04001000

ENABLE_3D = bit.blshift(1, 3)
DISPLAY_ENABLE_SHIFT = 8
DISPLAY_BG0_ACTIVE = bit.blshift(1, 8)
DISPLAY_BG1_ACTIVE = bit.blshift(1, 9)
DISPLAY_BG2_ACTIVE = bit.blshift(1, 10)
DISPLAY_BG3_ACTIVE = bit.blshift(1, 11)
DISPLAY_SPR_ACTIVE = bit.blshift(1, 12)
DISPLAY_WIN0_ON = bit.blshift(1, 13)
DISPLAY_WIN1_ON = bit.blshift(1, 14)
DISPLAY_SPR_WIN_ON = bit.blshift(1, 15)

-- //The allowed video modes of the 2D processors\\ --

MODE_0_2D =  0x10000 -- //4 2D backgrounds\\ --
MODE_1_2D =  0x10001 -- //4 2D backgrounds\\ --
MODE_2_2D = 0x10002 -- //4 2D backgrounds\\ --
MODE_3_2D = 0x10003 -- //4 2D backgrounds\\ --
MODE_4_2D = 0x10004 -- //4 2D backgrounds\\ --
MODE_5_2D = 0x10005 -- //4 2D backgrounds\\ --
MODE_6_2D = 0x10006 -- //4 2D backgrounds\\ --
MODE_0_3D = bit.bor(0x10000, bit.bor(DISPLAY_BG0_ACTIVE, ENABLE_3D)) -- //3 2D backgrounds 1 3D background (Main engine only)\\ --
MODE_1_3D = bit.bor(0x10001, bit.bor(DISPLAY_BG0_ACTIVE, ENABLE_3D)) -- //3 2D backgrounds 1 3D background (Main engine only)\\ --
MODE_2_3D = bit.bor(0x10002, bit.bor(DISPLAY_BG0_ACTIVE, ENABLE_3D)) -- //3 2D backgrounds 1 3D background (Main engine only)\\ --
MODE_3_3D = bit.bor(0x10003, bit.bor(DISPLAY_BG0_ACTIVE, ENABLE_3D)) -- //3 2D backgrounds 1 3D background (Main engine only)\\ --
MODE_4_3D = bit.bor(0x10004, bit.bor(DISPLAY_BG0_ACTIVE, ENABLE_3D)) -- //3 2D backgrounds 1 3D background (Main engine only)\\ --
MODE_5_3D = bit.bor(0x10005, bit.bor(DISPLAY_BG0_ACTIVE, ENABLE_3D)) -- //3 2D backgrounds 1 3D background (Main engine only)\\ --
MODE_6_3D = bit.bor(0x10006, bit.bor(DISPLAY_BG0_ACTIVE, ENABLE_3D)) -- //3 2D backgrounds 1 3D background (Main engine only)\\ --

MODE_FIFO = bit.blshift(3, 16) -- //video display from main memory\\ --

MODE_FB0 = 0x00020000 -- //video display directly from VRAM_A in LCD mode\\ --
MODE_FB1 = 0x00060000 -- //video display directly from VRAM_B in LCD mode\\ --
MODE_FB2 = 0x000A0000 -- //video display directly from VRAM_C in LCD mode\\ --
MODE_FB3 = 0x000E0000 -- //video display directly from VRAM_D in LCD mode\\ --

-- //main display only\\ --

DISPLAY_SPR_HBLANK = bit.blshift(1, 23)

DISPLAY_SPR_1D_LAYOUT = bit.blshift(1, 4)

DISPLAY_SPR_1D = bit.blshift(1, 4)
DISPLAY_SPR_2D = bit.blshift(0, 4)
DISPLAY_SPR_1D_BMP = bit.blshift(4, 4)
DISPLAY_SPR_2D_BMP_128 = bit.blshift(0, 4)
DISPLAY_SPR_2D_BMP_256 = bit.blshift(2, 4)

DISPLAY_SPR_1D_SIZE_32 = bit.blshift(0, 20)
DISPLAY_SPR_1D_SIZE_64 = bit.blshift(1, 20)
DISPLAY_SPR_1D_SIZE_128 = bit.blshift(2, 20)
DISPLAY_SPR_1D_SIZE_256 = bit.blshift(3, 20)
DISPLAY_SPR_1D_BMP_SIZE_128 = bit.blshift(0, 22)
DISPLAY_SPR_1D_BMP_SIZE_256 = bit.blshift(1, 22)

-- //mask to clear all attributes related to sprites from display control\\ --
DISPLAY_SPRITE_ATTR_MASK = bit.bor(bit.blshift(7, 4), bit.bor(bit.blshift(7, 20), bit.blshift(1, 31)))

DISPLAY_SPR_EXT_PALETTE = bit.blshift(1, 31)
DISPLAY_BG_EXT_PALETTE = bit.blshift(1, 30)

DISPLAY_SCREEN_OFF = bit.blshift(1, 7)

-- //The next two defines only apply to MAIN 2d engine\\ --
-- //In tile modes, this is multiplied by 64KB and added to BG_TILE_BASE\\ --
-- //In all bitmap modes, it is not used\\ --
function DISPLAY_CHAR_BASE(n) return bit.blshift(bit.band(n, 7), 24) end

-- //In tile modes, this is multiplied by 64KB and added to BG_MAP_BASE\\ --
-- //In bitmap modes, this is multiplied by 64KB and added to BG_BMP_BASE\\ --
-- //In large bitmap modes, this is not used\\ --
function DISPLAY_SCREEN_BASE(n) return bit.blshift(bit.band(n, 7), 27) end

function Video.getMode() return bit.band(REG_DISPCNT, 0x30007) end
function Video.getModeSub() return bit.band(REG_DISPCNT_SUB, 0x30007) end

function Video.bgEnable(number) REG_DISPCNT = bit.bor(REG_DISPCNT, bit.blshift(1, DISPLAY_ENABLE_SHIFT+number)) end
function Video.bgEnableSub(number) REG_DISPCNT_SUB = bit.bor(REG_DISPCNT_SUB, bit.blshift(1, DISPLAY_ENABLE_SHIFT+number)) end
function Video.bgDisable(number) REG_DISPCNT = bit.band(REG_DISPCNT, bit.bnot(bit.blshift(1, DISPLAY_ENABLE_SHIFT+number))) end
function Video.bgDisableSub(number) REG_DISPCNT_SUB = bit.band(REG_DISPCNT_SUB, bit.bnot(bit.blshift(1, DISPLAY_ENABLE_SHIFT+number))) end
